package com.aisino.api.util;

import java.net.InetAddress;

/**
 * @description:
 * @author: 陈兵
 * @date: 2025/8/23 21:31
 * @version: 1.0
 */
public class DefaultIdentifierGenerator implements IdentifierGenerator {
    private final Sequence sequence;

    /**
     * @deprecated
     */
    @Deprecated
    public DefaultIdentifierGenerator() {
        this.sequence = new Sequence((InetAddress) null);
    }

    public DefaultIdentifierGenerator(InetAddress inetAddress) {
        this.sequence = new Sequence(inetAddress);
    }

    public DefaultIdentifierGenerator(long workerId, long dataCenterId) {
        this.sequence = new Sequence(workerId, dataCenterId);
    }

    public DefaultIdentifierGenerator(Sequence sequence) {
        this.sequence = sequence;
    }

    public Long nextId(Object entity) {
        return this.sequence.nextId();
    }

    public static DefaultIdentifierGenerator getInstance() {
        return DefaultInstance.INSTANCE;
    }

    private static class DefaultInstance {
        public static final DefaultIdentifierGenerator INSTANCE = new DefaultIdentifierGenerator();
    }
}